<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<style>
    .table-border tbody tr td{
        border-top: 1px solid black;
    }
</style>
<div class="modal fade" id="modal-confirm">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">提交报价</h4>
            </div>
            <div class="modal-body">
                <label class="col-sm-12 control-label" style="font-size: 20px; text-align: left">确认提交此报价吗？</label>
                <form id="form-confirm" class="form-horizontal" role="form">
                    <input type="hidden" name="quoteId">
                    <div class="form-group">
                        <label class="col-sm-3 control-label" style="padding-left:30px;padding-right:0px; text-align: left ">批次信息备注：</label>
                        <div class="col-sm-9" style="padding-left:0px;padding-right:30px;">
                            <input type="text" class="form-control" name="qttBatchRemk" placeholder="请输入批次信息备注">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-submit">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="modal-updateCreateAccount">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改创建人</h4>
            </div>
            <div class="modal-body">
                <form id="form-updateCreateAccount" class="form-horizontal" role="form">
                    <input type="hidden" name="quoteId">
                    <div class="form-group">
                        <label class="col-sm-3 control-label" style="padding-left:30px;padding-right:0px; text-align: left ">报价创建人</label>
                        <div class="col-sm-9" style="padding-left:0px;padding-right:30px;">
                            <select name="createAccount" class="form-control" id="createAccount">
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-updateCreateAccount">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </button>
            </div>
        </div>
    </div>
</div>

<section class="content-header">
    <h1>报价单提交</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="proCode" class="form-control" placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="proName" class="form-control" placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>报价版本类型</label>
                                    <select name="quoteAvaStatus" class="form-control"  onchange="changeQuoteStatus(this.value)">
                                        <option value="">全部</option>
                                        <option value=1 selected="selected">临时报价</option>
                                        <option value=2>最终报价</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>报价状态</label>
                                    <select name="quoteStatus" class="form-control" id="quoteStatus">
                                        <option  value="1" selected="selected">未提交</option>
                                        <!--<option  value="22">待组级审</option>-->
                                        <option  value="23">待科级审</option>
                                        <!--<option  value="24">待部级审</option>-->
                                        <option  value="100">已提交</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>创建人</label>
                                    <input type="text" name="createName" class="form-control" placeholder="">
                                </div>
                                <div class="form-group">
                                    <label>创建日期</label>
                                    <input type="text" class="form-control datepicker" name="quoteStartDate"
                                           placeholder="请选择">
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" name="quoteEndDate"
                                           placeholder="请选择">
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">
                                    <span class="Bold">&emsp;搜索&emsp;</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" class = "table-border"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    /**
     *提交报价
     */
    function submitQuotation(quoteId) {
        $("#form-confirm  input[name ='quoteId']").val(quoteId);
        js.modal.open("modal-confirm");
    }

    /**
     * 修改创建人打开模态框
     */
    function updateCreateAccount(quoteId) {
        js.post({
            url: ctx + "quoteManage/updateCreateAccount/selectSysUser",
            success: function (result) {
                var mySelect = document.getElementById("createAccount"); //得到select的ID
                mySelect.options.length=0;
                mySelect.options.add(new Option("请选择", 0));
                debugger
                for (var i = 0; i < result.data.length; i++) {
                    debugger
                    var parkdata = result.data[i];
                    mySelect.options.add(new Option(parkdata.name, parkdata.account));
                }
             $("#form-updateCreateAccount  input[name ='quoteId']").val(quoteId);
             js.modal.open("modal-updateCreateAccount");
            }
        })
    }

    /**
     *删除报价
     */
    function delQuotation(quoteId) {
        js.modal.confirm("确认删除此报价吗？", function () {
            js.post({
                url: ctx + "quoteManage/quotationManage/del",
                data: {
                    quoteId: quoteId
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        window.parent.getItemCount();
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            })
        })
    }

    //报价任务状态更改时，更改报价执行状态
    function changeQuoteStatus(quoteValue){
        debugger
        if(quoteValue == 2){
            $("#quoteStatus").val('100');
            $("#quoteStatus").prop("disabled", true);

        }else {
            $("#quoteStatus").val('1');
            $("#quoteStatus").prop("disabled", false);
        }
    }

    var table;
    $(function () {
        /**
         * 加载列表
         */
        table = js.table.init({
            url: ctx + "quoteManage/quotationManage/list",
            showColumns: true,
            showExport: true,
            onLoadSuccess: function (data) {
                var dataSource = $('#bootstrap-table').bootstrapTable('getData', true);
            },
            columns: [
                {
                    title: '序号', field: 'id', width: '80',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: '项目编号', field: 'proCode', width: '180',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value.split(',').join('<br>');
                        }
                    }
                },
                {title: '项目名称', field: 'proName', width: '300',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value.split(',').join('<br>');
                        }
                    }
                },
                {
                    title: '物料名称', field: 'proNames', width: '300',
                    formatter: function (value, row, index, field) {
                        if (value != null) {
                            return value.split(',').join('<br>');
                        }
                    }
                },
                {title: '买方名称', field: 'consumerName', width: '270px'},

                // {title: '任务组', field: 'groupName', width: '200',
                //     formatter: function (value, row, index) {
                //         if (value != null) {
                //             return value.split(',').join('<br>');
                //         }
                //     }
                // },
                // {
                //     title: '概算状态', field: 'budgetProcessStatus', width: '100',
                //     formatter: function (value, row, index) {
                //         if (value === 1) {
                //             return '<span class="badge ' + ["label-default"] + '">' + '未开始' + '</span> ';
                //         } else if (value === 2) {
                //             return '<span class="badge ' + ["label-info"] + '">' + '执行中' + '</span> ';
                //         } else if (value === 3) {
                //             return '<span class="badge ' + ["label-success"] + '">' + '已完成' + '</span> ';
                //         }
                //     }
                // },
                {
                    title: '报价版本</br>类型', field: 'quoteAvaStatus', width: '120',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge ' + ["label-warning"] + '">' + '临时报价' + '</span> ';
                        } else if (value === 2) {
                            return '<span class="badge ' + ["label-success"] + '">' + '最终报价' + '</span> ';
                        } else {
                            return ;
                        }
                    }
                },
                {
                    title: '报价执<br>行状态', field: 'quoteStatus', width: '120',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge ' + ["label-default"] + '">' + '未提交' + '</span> ';
                        } else if (value === 2 || value === 3) {
                            return '<span class="badge ' + ["label-info"] + '">' + '执行中' + '</span> ';
                        } else if (value === 4) {
                            return '<span class="badge ' + ["label-success"] + '">' + '审核通过' + '</span> ';
                        }else if (value === 5) {
                            return '<span class="badge ' + ["label-danger"] + '">' + '审核驳回' + '</span> ';
                        }
                    }
                },
                // {title: '报价单编号', field: 'quoteNo', width: '150px'},

                {title: '含税</br>总金额(元)', field: 'totalAmountIncludedTax', width: '120px'},
                {title: '创建人', field: 'createName', width: '120px'},
                {title: '创建日期', field: 'quoteGentDate', width: '120px'},
                {
                    title: '操作', field: 'operation', width: '110',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if(hasP("quo:await:view")) {
                            actions.push('<a class="btn btn-info btn-xs" href="' + ctx + 'quoteManage/viewQuotation/quoteId/' + row.quoteId + '">查看</a> ');
                        }
                        if (row.quoteStatus == 1 ||row.quoteStatus == 5) {
                            if(
                                [[${sysUserModel.orgId}]]!= null &&
                                [[${sysUserModel.account}]] == row.createAccount){
                                if (hasP("quo:com:edit")) {
                                actions.push('<a class="btn btn-warning btn-xs" href="' + ctx + 'quoteManage/editQuotation/' + row.quoteId + '">修改</a> ');
                                }
                                if (hasP("quo:com:commit")) {
                                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="submitQuotation(' + row.quoteId + ')"> 提交</a>');
                                }
                            }
                        }
                        if (row.quoteStatus == 1) {
                            if ([[${sysUserModel.orgId}]] != null && [[${sysUserModel.account}]] == row.createAccount) {
                                if (hasP("quo:com:edit")) {
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="delQuotation(' + row.quoteId + ')"> 删除</a>');
                                }
                            }
                        }
                        if (row.quoteStatus == 1 ||row.quoteStatus == 5) {
                            if (
                                [[${sysUserModel.orgId}]] != null &&
                                [[${sysUserModel.account}]] == row.createAccount) {
                                if (hasP("quo:com:edit")) {
                                    actions.push('<a class="btn btn-bitbucket btn-xs" href="javascript:void(0)"  onclick="updateCreateAccount(' + row.quoteId + ')">修改创建人</a> ');
                                }
                            }
                        }
                        return actions.join('');
                    }
                }
            ]
        });

        //提交报价
        $("#btn-submit").click(function () {
                js.submit({
                    url: ctx + "quoteManage/quotationManage/submit",
                    data:
                        new FormData($("#form-confirm")[0]),
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            js.modal.success(result.msg);
                            window.parent.getItemCount();
                            js.modal.hide("modal-confirm");
                            js.table.refresh(table);
                        } else {
                            js.modal.warning(result.msg);
                        }
                        js.modal.closeLoading();
                    }
                })
        });

        //提交修改创建人
        $("#btn-updateCreateAccount").click(function () {
            js.submit({
                url: ctx + "quoteManage/updateCreateAccount",
                data:
                    new FormData($("#form-updateCreateAccount")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.modal.hide("modal-updateCreateAccount");
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            })
        });

        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-confirm", function () {
            js.reset("form-confirm");
        });

        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

    });
</script>
</body>
</html>